﻿using System;
using System.Windows;
using System.Windows.Data;

namespace ChatTextBlockControlSample.Util
{
    public class UIHelper
    {
        public static void Debug(string message)
        {
            System.Diagnostics.Debug.WriteLine(message);
        }
    }

    /// <summary>
    /// Converter bool to visibility
    /// </summary>
    public class UIVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;
            try
            {
                if (parameter is string && parameter.ToString() == "Inverse")
                    value = !(bool)value;

                if ((bool)value)
                    return Visibility.Visible;
                else
                    return Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                UIHelper.Debug(ex.Message + "\r\n" + ex.StackTrace);
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// Converter bool to visibility
    /// </summary>
    public class UIHorizontalAlignmentConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;
            try
            {
                if ((bool)value)
                    return HorizontalAlignment.Left;
                else
                    return HorizontalAlignment.Right;
            }
            catch (Exception ex)
            {
                UIHelper.Debug(ex.Message + "\r\n" + ex.StackTrace);
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
